<?php
require_once("../includes/config.php");
include DIR_INCLUDES_FT.'bootstrap.php';
header('Content-type: text/html; charset=utf-8');

if(isset($_GET['id'])){
	$cliente = Doctrine::getTable("Clientes")->find($_GET['id']);
} else {
	$cliente = new Clientes();
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt" lang="pt" dir="ltr">
	<head>
		<?require(DIR_FT."header.php");?>
		<script type="text/javascript">
			$(document).ready(function(){
				$("#clientes_form").validate({
					rules: {
						nome: {
							required: true,
							minlength: 5,
							remote:{
								url: "clientes.serverside.php",
								type: "post",
								data: {id: $("#id").val(), accao:'verifica_cliente'}
							}
						}
					},
					submitHandler: function(form){
						agree = confirm('<?=FORM_COMMIT?>');
						if(agree){form.submit();}
					}
				});
			});
		</script>
	</head>
	<body>
	<?php require_once(DIR_MENUS_FT."menu.php");?>
	<div id="main_div">
		<form enctype="multipart/form-data" accept-charset="utf-8" id="clientes_form" action="clientes_form_edit.php" method="post">
			<fieldset id="form-area">
				<legend><?=CLIENTE?></legend>
				<label for="nome"><?=NOME?>:</label>
				<input type="text" id="nome" name="nome" value="<?=$cliente->nome?>" />

				<label for="descricao"><?=DESCRICAO?>:</label>
				<textarea id="descricao" name="descricao"><?=$cliente->descricao?></textarea>
				
				<input type="submit" name="submit" value="<?=GRAVAR?>" class="submit-button" />
				<div style="clear: both;"></div>
			</fieldset>
			<input type="hidden" name="id" id="id" value="<?=$cliente->id?>" />
		</form>
	</div>
	<?require(DIR_FT."footer.php");?>
	</body>
</html>